const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const baseConfig = require("./webpack.base.conf.js")
const config = require("./config.js")

const babelOptions = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          browsers: [
            'last 2 versions',
            'Firefox ESR',
            '> 1%',
            'ie >= 11',
            'iOS >= 8',
            'Android >= 4',
          ],
        },
      },
    ],
    '@babel/preset-typescript'
  ],
  plugins: [
    ['@vue/babel-plugin-jsx', { mergeProps: false }],
  ]
}
module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: baseConfig.entry,
  output: baseConfig.output,
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.tsx?$/,
        use: [
          {
            loader: 'babel-loader',
            options: babelOptions,
          },
          {
            loader: 'ts-loader',
          },
        ],
        exclude: /node_modules/,
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /pickr.*js/,
        loader: 'babel-loader',
        options: babelOptions
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'url-loader',
        options: {
          limit: 102400,
          outputPath: path.resolve(__dirname, '../dist/static/image')
        }
      },
      {
        test: /\.less$/,
        use: [
          { loader: 'style-loader' },
          {
            loader: 'css-loader',
          },
          {
            loader: 'less-loader',
            options: {
              lessOptions: {
                sourceMap: true,
                javascriptEnabled: true,
              }
            }
          }
        ]
      },
      {
        test: /\.css$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader
          },
          'css-loader',
        ],
      },
    ]
  },
  resolve: {
    ...baseConfig.resolve
  },
  devServer: {
    ...config.dev.server
  },
  plugins: [
    ...baseConfig.plugins
  ]
}